# buildit.sh
# script to build cd and install ramdisk images
# copyright (c) 2001 joseph cheek.  all rights reserved.
# released under gpl


# need > 1050 blocks free cd_ramdisk
# need > 2400 blocks free install_ramdisk

LANG=

if [ "n$1" = "n-l" ]; then # -l
  LANG="$2"
  shift
  shift
fi

if [ -z "$LANG"  ]; then
  echo -e `basename $0` \[-l lang\]: need lang \\a
  exit 1
fi

# /
echo -e Rootdisk \  \ \ : Desktop/LX Personal \(Linux `uname -r` \
  common\) \#`cat /opt/redmondlinux/builds/CURRENT_BUILD` \
  `date +%d%b%y` > IDENTIFY

cd /tmp
cp /opt/redmondlinux/builds/current/$LANG/floppy/linuxrc .
perl -pi -e s/^\\s*//g linuxrc
perl -pi -e s/^\\#.*/\\#/g linuxrc
mv linuxrc linuxrc.new
echo \#\!/bin/sh > linuxrc
cat linuxrc.new >> linuxrc
rm linuxrc.new
perl -pi -e s/FILE_LOG_DEBUG/FLD/g linuxrc
perl -pi -e s/CMD_BOOTER/BTR/g     linuxrc
perl -pi -e s/DIR_TARGET/DT/g      linuxrc
cd -
cp /tmp/linuxrc .
chmod 555 linuxrc

# boot

cp /boot/stage3.pcx boot/stage3.pcx

# dev

# etc

# grep -B 9999 ISAPnP < /usr/share/hwprobe/linux-kernel-ids |
cat < /usr/share/hwprobe/linux-kernel-ids |
  cut -d \# -f 1 | tr -s \\n | tr -d \\t > etc/pcidrivers

# modules

# drivers

NEWMODDIR=lib/modules/`uname -r`/kernel/drivers  # no /; local
REALMODDIR=/lib/modules/`uname -r`/kernel/drivers  # note /; from root

rm -rf /mnt/cd_ramdisk/lib/modules # dangerous?
mkdir -p $NEWMODDIR

for a in block cdrom ide net parport pnp scsi sound usb; do

  [ -d $NEWMODDIR/$a ] || mkdir -p $NEWMODDIR/$a

  case "$a" in

    block)
      COPY=loop*
      ;;

    cdrom)
      COPY=cdrom*
      ;;

    ide)
#      COPY=ide-cd*
      COPY=ide-floppy*
      ;;

    net)
      COPY="*.o tulip/*.o"
      ;;

    parport)
      COPY=*
      ;;

    pnp)
      COPY=isa-pnp*
      ;;

    scsi)
      COPY="*.o aic7xxx/*.o"
      ;;

    sound)
      COPY=sound*
      ;;

    usb)
      COPY="usbcore* usb-?hci* storage/*"
      ;;

  esac

set -f  # turn off glob expansion
  for b in $COPY; do
set +f  # turn it back on

    for c in `echo $REALMODDIR/$a/$b`; do
      gzip --best $c -c > $NEWMODDIR/$a/`basename $c`.gz
    done
  done

done

# e100
gzip --best -c $REALMODDIR/../../net/e100.o > $NEWMODDIR/net/e100.o.gz

# NEED... MORE... SPACE...
 
rm lib/modules/*/kernel/drivers/scsi/{dmx3191d,eata*,megaraid,*st}.o.gz

# fs

mkdir -p lib/modules/`uname -r`/kernel/fs
for a in fat isofs msdos vfat; do # umsdos nfs lockd
  gzip --best /lib/modules/`uname -r`/kernel/fs/$a/$a.o -c \
    > lib/modules/`uname -r`/kernel/fs/$a.o.gz
done

# net

# if we're getting rid of nfs, we don't need this...
# mkdir -p lib/modules/`uname -r`/kernel/net/sunrpc
# gzip --best /lib/modules/`uname -r`/kernel/net/sunrpc/sunrpc.o -c \
#   > lib/modules/`uname -r`/kernel/net/sunrpc/sunrpc.o.gz


# 
# 
# copy stuff to install_ramdisk

rm -rf ../install_ramdisk/*
cp -a * ../install_ramdisk

# need more space on cd_ramdisk - HACK

rm lib/modules/`uname -r`/kernel/drivers/scsi/ql*
rm lib/modules/`uname -r`/kernel/drivers/usb/usb-storage*

for a in airo ppp 8390 arlan bonding bsd cs89 eql eepro100 es3210 \
  fealnx lne390 lp486e natsemi ne2 ne32 ni50 plip rcpci sb1000 \
  shaper slhc slip smc starfire strip sundance tun \
  via-rhine wavelan winbond; do
  rm lib/modules/`uname -r`/kernel/drivers/net/$a*.gz
done

# need more space on install_ramdisk

cd ../install_ramdisk/lib/modules/`uname -r`/kernel/drivers/scsi
rm [3-hj-rt-z]* i[a-ce-z]* s[abd-qs-z]*
# all but ide-scsi, scsi_mod, sr_mod

cd ..
rm -rf net parport pnp sound usb
cd ..
rm -rf fs/umsdos* fs/lockd* fs/nfs* net
cd ../../../..
rm -f bin/mol.gz buildit.sh sbin/fdisk.gz
